#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'检测编码的工具'

import chardet

str1 = 'dsakdlkal'.encode('utf-8')
str2 = '离离原上草，一岁一枯荣'.encode('gbk')
str3 = b'dcasdcs'

print(chardet.detect(str1))  # {'encoding': 'ascii', 'confidence': 1.0, 'language': ''}
print(chardet.detect(str2))  # {'encoding': 'GB2312', 'confidence': 0.7407407407407407, 'language': 'Chinese'}
print(chardet.detect(str3))  # {'encoding': 'ascii', 'confidence': 1.0, 'language': ''}
